Skip to content

[Others] Add NUM_MAX_DISPATCH_TOKENS_PER_RANK env to control#7188

Closed
RichardWooSJTU wants to merge 1 commit intoPaddlePaddle:developfrom
RichardWooSJTU:add_env
Closed

[Others] Add NUM_MAX_DISPATCH_TOKENS_PER_RANK env to control#7188
RichardWooSJTU wants to merge 1 commit intoPaddlePaddle:developfrom
RichardWooSJTU:add_env

Conversation

@RichardWooSJTU
Copy link
Copy Markdown
Collaborator

@RichardWooSJTU RichardWooSJTU commented Apr 3, 2026

Motivation

当前低时延EP通信所需要的num_max_dispatch_tokens_per_rank参数只能通过model目录中的config.json指定,在上线等场景下不方便改动。

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Modifications

增加NUM_MAX_DISPATCH_TOKENS_PER_RANK 环境变量,和config.json中的配置优先级相同,如果和config.json中的配置冲突的话会抛出错误。

Usage or Command

export NUM_MAX_DISPATCH_TOKENS_PER_RANK=256

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 3, 2026

Thanks for your contribution!

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@938e7dd). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/config.py 14.28% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7188   +/-   ##
==========================================
  Coverage           ?   73.24%           
==========================================
  Files              ?      376           
  Lines              ?    52946           
  Branches           ?     8263           
==========================================
  Hits               ?    38779           
  Misses             ?    11453           
  Partials           ?     2714           
Flag Coverage Δ
GPU 73.24% <14.28%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@fastdeploy-bot fastdeploy-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-09

📋 Review 摘要

PR 概述:新增 NUM_MAX_DISPATCH_TOKENS_PER_RANK 环境变量,用于控制 MoE 计算中每 rank 的最大调度 token 数量。

变更范围:fastdeploy/envs.py、fastdeploy/config.py

影响面 Tag[Others]


📝 PR 规范检查

标题:使用了 [Others] 标签,符合规范。

描述:Motivation 和 Modifications 部分仅包含模板文字,未填写实际内容,不符合规范。

描述模板(请补充):

## Motivation

[说明为什么要添加这个环境变量,例如:允许在不修改模型配置的情况下调整 MoE 调度参数,便于性能调优...]

## Modifications

[详细说明修改内容,例如:1. 在 envs.py 中新增 NUM_MAX_DISPATCH_TOKENS_PER_RANK 环境变量;2. 在 config.py 中添加一致性检查逻辑...]

问题

级别 文件 概述
🟡 建议 fastdeploy/envs.py:271 环境变量命名不符合项目规范
🟡 建议 fastdeploy/envs.py:272 缺少对环境变量值的验证
🟡 建议 fastdeploy/config.py:270 缺少单元测试覆盖新增逻辑

总体评价

代码逻辑清晰,实现了环境变量与模型配置的一致性检查机制。但存在命名规范、输入验证和测试覆盖方面的问题需要改进。

),
# Number of max dispatch tokens per rank for MoE computation.
# If set, it must match the value in model config if present, otherwise an error will be raised.
"NUM_MAX_DISPATCH_TOKENS_PER_RANK": lambda: (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 环境变量命名不符合项目规范。

项目中的环境变量统一使用 FD_ 前缀(如 FD_MOE_BACKENDFD_MOE_MXFP4_BACKEND),建议将此变量重命名为 FD_NUM_MAX_DISPATCH_TOKENS_PER_RANK

# Number of max dispatch tokens per rank for MoE computation.
# If set, it must match the value in model config if present, otherwise an error will be raised.
"NUM_MAX_DISPATCH_TOKENS_PER_RANK": lambda: (
int(os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK", "0"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 缺少对环境变量值的验证。

当环境变量设置为 0 或负数时可能导致问题。建议添加验证:

"NUM_MAX_DISPATCH_TOKENS_PER_RANK": lambda: (
    int(value) if (value := os.getenv("NUM_MAX_DISPATCH_TOKENS_PER_RANK")) and int(value) > 0
    else None
),

)
else:
# Use env value if model config doesn't explicitly set it
self.num_max_dispatch_tokens_per_rank = env_num_max_dispatch
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 缺少单元测试覆盖新增逻辑。

建议在 tests/utils/test_config.py 中添加测试用例,验证以下场景:

  1. 环境变量未设置时使用默认值 128
  2. 环境变量设置时,与模型配置不一致时抛出 ValueError
  3. 环境变量设置时,模型配置未设置时使用环境变量值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants